/*
 * @文件描述:
 * @版本:
 * @作者: 周晨阳
 * @Date: 2021-01-16 09:42:28
 */
#ifndef OSCILLOSCOPE_H
#define OSCILLOSCOPE_H

#include <stdio.h>
#include <stdlib.h>
#include "myADC.h"

#define H_SCALE_CNT 28

#define H_SCALE_1NS 1
#define H_SCALE_2NS 2
#define H_SCALE_5NS 3
#define H_SCALE_10NS 4
#define H_SCALE_20NS 5
#define H_SCALE_50NS 6
#define H_SCALE_100NS 7
#define H_SCALE_200NS 8
#define H_SCALE_500NS 9
#define H_SCALE_1US 10
#define H_SCALE_2US 11
#define H_SCALE_5US 12
#define H_SCALE_10US 13
#define H_SCALE_20US 14
#define H_SCALE_50US 15
#define H_SCALE_100US 16
#define H_SCALE_200US 17
#define H_SCALE_500US 18
#define H_SCALE_1MS 19
#define H_SCALE_2MS 20
#define H_SCALE_5MS 21
#define H_SCALE_10MS 22
#define H_SCALE_20MS 23
#define H_SCALE_50MS 24
#define H_SCALE_100MS 25
#define H_SCALE_200MS 26
#define H_SCALE_500MS 27
#define H_SCALE_1S 28

#define V_SCALE_CNT 12

#define V_SCALE_5V 12
#define V_SCALE_2V 11
#define V_SCALE_1V 10
#define V_SCALE_500mV 9
#define V_SCALE_200mV 8
#define V_SCALE_100mV 7
#define V_SCALE_50mV 6
#define V_SCALE_20mV 5
#define V_SCALE_10mV 4
#define V_SCALE_5mV 3
#define V_SCALE_2mV 2
#define V_SCALE_1mV 1

//示波器状态
//示波器正在连续采样
#define STATE_RUNNING 1
//示波器hold功能
#define STATE_HOLD 2

//触发系统状态
//触发的
#define TRIGGER_STATE_TRIGGERED 3
//自动
#define TRIGGER_STATE_AUTO 4
//普通触发
#define TRIGGER_STATE_NORMAL 5
//单次触发
#define TRIGGER_STATE_SINGLE 6

#define CURSOR_1 0
#define CURSOR_2 1
#define CURSOR_3 2
#define CURSOR_4 3
#define CURSOR_5 4
//光标类型，x类型
#define CURSOR_TYPE_X 1
//y类型
#define CURSOR_TYPE_Y 2
//触发光标类型
#define CURSOR_TYPE_TRIGGER 3

#define INTERPOLATION_SINC 1
#define INTERPOLATION_LINEAR 2

#define VOLTAGE_MEASURE_CNT 4

#define VOLTAGE_MEASURE_VPP 0
#define VOLTAGE_MEASURE_VMIN 1
#define VOLTAGE_MEASURE_VMAX 2
#define VOLTAGE_MEASURE_VRMS 3

#define TIME_MEASURE_CNT 1

#define TIME_MEASURE_FREQ (VOLTAGE_MEASURE_CNT + 0)

#define MEASURE_TOTAL_CNT (VOLTAGE_MEASURE_CNT + TIME_MEASURE_CNT)
void Oscil_Init(void);
void oscillLooper(void);
void openOscil(void);
void closeOscil(void);
float getVoltageMeasure(uint8_t measureType);
float getTimeMeasure(uint8_t measureType);
void setOscilH_Scale(uint8_t scale);
void setOscilV_Scale(uint8_t scale);
uint8_t getOscilHoriScale();
uint8_t getOscilVertiScale();
void setOscilTrigType(uint8_t type);
void setOscilTrigVoltage(float voltage);
void setOscilH_Pos(int pos);
void setOscilV_Pos(int pos);
int getOscilH_Pos(void);
int getOscilV_Pos(void);

void setRunningState(uint8_t state);
uint8_t getRunningState(void);
void holdTrigger(void);
void showCursor(unsigned char which);
void hideCursor(unsigned char which);
void setCursorPos(uint8_t which, uint16_t posX);
uint16_t getCursorPos(uint8_t which);
float getValueByCursor(uint8_t which, uint16_t posX);
uint8_t getTriggerState(void);
void setStorageDepth(uint32_t depth);
uint32_t getStorageDepth(void);
void measureFreqProcess(void);
void autoMeasure(void);
float getOscilTrigVoltage(void);
uint8_t getOscilTrigType(void);
void registerOscillButton();
void cancelOscillButton();
#endif